import {AxiosInstance} from 'axios';
import axios from 'axios'

const instance: AxiosInstance = axios.create({
  baseURL: 'http://localhost:8081/goodstype',
  timeout: 2000,
  headers: {
    'Content-type': 'application/json'
  },

  withCredentials: true
})

class GoodsTypeService {
  static async findAll() {
    let response = await instance.get('/')
    return response.data
  }

  static async insertOne(goodsType: GoodsType) {
    let response = await instance.post('/', JSON.stringify(goodsType))
    return response.data
  }

  static async deleteOne(id: number) {
    let response = await instance.delete('/', {
      params: {
	id
      }
    })
    return response.data
  }

  static async updateOne(goodsType: GoodsType) {
    let response = await instance.put('/', JSON.stringify(goodsType))
    return response.data
  }
}

export default GoodsTypeService